package com.wc.算法基础课.C第三讲搜索与图论.BFS.八数码2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/**
 * @Author congge
 * @Date 2024/3/16 21:44
 * @description https://www.acwing.com/problem/content/description/181/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static char[] cs = new char[9];
    static int[] dx = new int[]{-1, 1, 0, 0};
    static int[] dy = new int[]{0, 0, -1, 1};
    static char[] op = new char[]{'u', 'd', 'l', 'r'};
    static String end;

    public static void main(String[] args) {
        for (int i = 0; i < 9; i++) cs[i] = sc.next().charAt(0);
        end = "12345678x";
        String res = bfs();
        if (res == null) out.println("unsolvable");
        else out.println(res);
        out.flush();
    }

    static String bfs() {
        Queue<String> q = new LinkedList<>();
        q.add(new String(cs));
        Map<String, StringBuffer> paths = new HashMap<>();
        paths.put(new String(cs), new StringBuffer());

        while (!q.isEmpty()) {
            String t = q.poll();
            if (t.equals(end)) return paths.get(t).toString();
            int p = t.indexOf('x');
            cs = t.toCharArray();
            int x = p / 3;
            int y = p % 3;
            for (int i = 0; i < 4; i++) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (nx < 0 || nx > 2 || ny < 0 || ny > 2) continue;
                swap(cs, p, nx * 3 + ny);
                String s = new String(cs);
                if (!paths.containsKey(s)) {
                    StringBuffer tmp = new StringBuffer(paths.get(t));
                    tmp.append(op[i]);
                    paths.put(s, tmp);
                    q.add(s);
                }
                swap(cs, p, nx * 3 + ny);
            }
        }

        return null;
    }

    static void swap(char[] cs, int i, int j) {
        char tmp = cs[i];
        cs[i] = cs[j];
        cs[j] = tmp;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
